*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 
gl path5 = "$MAIN/Marriage/Restat/dataverse_files/Data" 

gl CONTROL = " year_birth sex#age urban_hk prov_hk##c.(year_birth ) "

use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3)


drop if mi(hktype)
replace urban = hktype == 1 
su age 

cap gen female = 1-male
cap gen han = 1- minority 

replace unmarried = unmarried * 100 
gen unmarr_25 = marr_age > 25 if !mi(marr_age)
replace unmarr_25 = 1 if unmarried == 100 
replace unmarr_25 = unmarr_25 *100 

gen urban_hk = hktype == 2 

egen clsid = group(prov_hk year_birth)

gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 
keep if Other == 0 

egen n_birth = rowtotal(numbirm numbirf)
replace n_birth = . if age > 45
replace n_birth = . if sex == 1 

egen fine_16_20 = rowmean(fine_16 fine_17 fine_18 fine_19 fine_20)


forvalues a = 26(1)40{
gen unmarr_`a' = marr_age > `a' if !mi(marr_age) & age >= `a' 
replace unmarr_`a' = 1 if unmarried == 100 & age >= `a'
replace unmarr_`a' = unmarr_`a' * 100 
}
replace HM = . if unmarried == 100

forvalues a = 25(1)40{
gen HM_`a' = HM   if age >= `a' 

}


su unmarr* HM

gen mino_nopolicy = 1- mino_policy

**** Appendix Table A4 ****
cap erase "$path3/marriage_dynamic_unmarr.xls"
cap erase "$path3/marriage_dynamic_unmarr.txt"

foreach eth in "han" "minority"  {
forvalues a = 26(1)40{
foreach y_var in "unmarr_`a'" {

reghdfe `y_var' fine_16_25 if `eth' & age > `a'  [aw = aw], a($CONTROL)  cluster(prov_hk)
su `y_var'  if `eth' & age > `a'  [aw = aw]
outreg2 using "$path3/marriage_dynamic_unmarr.xls", append addstat(Y, `r(mean)')  keep(fine_16_25) dec(3) bracket  ctit(`y_var' & `eth' )



}
}
}

**** Appendix Table A9 ****

cap erase "$path3/marriage_dynamic_HM.xls"
cap erase "$path3/marriage_dynamic_HM.txt"

foreach eth in "minority" "han"  {
foreach policy in   "mino_policy" "mino_nopolicy"{
forvalues a = 26(1)40{
foreach y_var in  "HM_`a'" {

reghdfe `y_var' fine_16_25 if `eth' & age > `a' & `policy' [aw = aw], a($CONTROL)  cluster(prov_hk)
su `y_var'  if `eth' & age > `a' & `policy' [aw = aw]
outreg2 using "$path3/marriage_dynamic_HM.xls", append addstat(Y, `r(mean)')  keep(fine_16_25) dec(3) bracket  ctit(`y_var' & `policy' )


}
}
}
}


**** Appendix Figure A6 ****


use "$path5\unmarr_coef.dta", clear 


foreach sample in  "han_noedu" "mino_noedu"{
gen up_`sample' = coef_`sample' + 1.65*se_`sample'
gen low_`sample' = coef_`sample' - 1.65*se_`sample'
}



tw (con coef_han_noedu coef_mino_noedu age, m(O T) lp(longdash longdash) yline(0) xlabel(26(1)40) ///
xtit("Age") ytit("Impact of fines on unmarried status at the corresponding age (%)") ylabel(-2(1)4, grid)) ///
(rarea up_han_noedu low_han_noedu age,lc(none) lp(dash) color(dkgreen%15)) (rarea up_mino_noedu low_mino_noedu age,lc(none) lp(dash) color(orange_red%15) ///
legend(label(1 "Han") label(2 "Minority") label(3 "90% CI") label(4 "90% CI") ring(0))) 
gr export "$path4\unmarr_dynamic_noedu.pdf", replace 


**** Appendix Figure A7 ****


use "$path5\HM_coef.dta", clear 

foreach sample in "han_pref" "mino_pref""han_nopref" "mino_nopref"{

gen up_`sample'_noedu = coef_`sample'_noedu + 1.65*se_`sample'_noedu
gen low_`sample'_noedu = coef_`sample'_noedu - 1.65*se_`sample'_noedu
}

foreach control in "_noedu" {
tw (con coef_han_pref`control' coef_han_nopref`control' age, m(O T) lp(longdash longdash) yline(0) xlabel(26(1)40) ///
xtit("Age") ytit("Impact of fines on H-M marriage (%)") ylabel(-0.5(0.5)2.5, grid)) ///
(rarea up_han_pref`control' low_han_pref`control' age, lc(none) lp(dash) color(dkgreen%15)) (rarea up_han_nopref`control' low_han_nopref`control' age, lc(none) lp(dash) color(orange_red%15) ///
legend(label(1 "Regions w/ pref policy") label(2 "Regions w/o pref policy") label(3 "90% CI") label(4 "90% CI") ring(0))) 
gr export "Graphics\H-M_han_dynamic`control'.pdf", replace 



tw (con coef_mino_pref`control' coef_mino_nopref`control' age, m(O T) lp(longdash longdash) yline(0) xlabel(26(1)40) ///
xtit("Age") ytit("Impact of fines on H-M marriage (%)") ylabel(-4(2)10, grid)) ///
(rarea up_mino_pref`control' low_mino_pref`control' age,lc(none) lp(dash) color(dkgreen%15)) (rarea up_mino_nopref`control' low_mino_nopref`control' age, lc(none) lp(dash) color(orange_red%15) ///
legend(label(1 "Regions w/ pref policy") label(2 "Regions w/o pref policy") label(3 "90% CI") label(4 "90% CI") ring(0))) 

gr export "Graphics\H-M_mino_dynamic`control'.pdf", replace 
}





